package org.pro.core.authentiction;


import org.pro.core.constant.SecurityConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

/**
 * 对form表单的验证
 * @author luoqiz
 *
 */
public class AbstractChannelSecurityConfig extends WebSecurityConfigurerAdapter {

	/**
	 * 验证码校验失败的处理器
	 */
	@Autowired
	protected AuthenticationFailureHandler authenticationFailureHandler;

	/**
	 * 验证码校验成功的处理器
	 */
	@Autowired
	protected AuthenticationSuccessHandler authenticationSuccessHandler;

	protected void applyPasswordAuthenticationConfig(HttpSecurity http) throws Exception {
		http.formLogin()
			.loginPage(SecurityConstants.DEFAULT_UNAUTHENTICATION_URL)
			.loginProcessingUrl(SecurityConstants.DEFAULT_LOGIN_PROCESSING_URL_FORM)
			.successHandler(authenticationSuccessHandler)
			.failureHandler(authenticationFailureHandler);
	}
}
